package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseModelResponse;
import java.io.File;
import com.ibm.risk.irmp.workflow.client.flowable.model.ModelRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.ModelResponse;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.ModelsApi")
public class ModelsApi {
    private ApiClient apiClient;

    public ModelsApi() {
        this(new ApiClient());
    }

    @Autowired
    public ModelsApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Create a model
     * All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only setting the name of the model, leaving all other fields null.
     * <p><b>200</b> - successful operation
     * <p><b>201</b> - Indicates the model was created.
     * @param body The body parameter
     * @return ModelResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ModelResponse createModel(ModelRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/repository/models").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<ModelResponse> returnType = new ParameterizedTypeReference<ModelResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Delete a model
     *
     * <p><b>204</b> - Indicates the model was found and has been deleted. Response-body is intentionally empty.
     * <p><b>404</b> - Indicates the requested model was not found.
     * @param modelId The modelId parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void deleteModel(String modelId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'modelId' is set
        if (modelId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'modelId' when calling deleteModel");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("modelId", modelId);
        String path = UriComponentsBuilder.fromPath("/repository/models/{modelId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get the extra editor source for a model
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     * <p><b>200</b> - Indicates the model was found and source is returned.
     * <p><b>404</b> - Indicates the requested model was not found.
     * @param modelId The modelId parameter
     * @return List&lt;byte[]&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<byte[]> getExtraEditorSource(String modelId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'modelId' is set
        if (modelId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'modelId' when calling getExtraEditorSource");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("modelId", modelId);
        String path = UriComponentsBuilder.fromPath("/repository/models/{modelId}/source-extra").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<byte[]>> returnType = new ParameterizedTypeReference<List<byte[]>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a model
     *
     * <p><b>200</b> - Indicates the model was found and returned.
     * <p><b>404</b> - Indicates the requested model was not found.
     * @param modelId The modelId parameter
     * @return ModelResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ModelResponse getModel(String modelId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'modelId' is set
        if (modelId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'modelId' when calling getModel");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("modelId", modelId);
        String path = UriComponentsBuilder.fromPath("/repository/models/{modelId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<ModelResponse> returnType = new ParameterizedTypeReference<ModelResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get the editor source for a model
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     * <p><b>200</b> - Indicates the model was found and source is returned.
     * <p><b>404</b> - Indicates the requested model was not found.
     * @param modelId The modelId parameter
     * @return List&lt;byte[]&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<byte[]> getModelBytes(String modelId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'modelId' is set
        if (modelId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'modelId' when calling getModelBytes");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("modelId", modelId);
        String path = UriComponentsBuilder.fromPath("/repository/models/{modelId}/source").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<byte[]>> returnType = new ParameterizedTypeReference<List<byte[]>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List models
     *
     * <p><b>200</b> - Indicates request was successful and the models are returned
     * <p><b>400</b> - Indicates a parameter was passed in the wrong format. The status-message contains additional information.
     * @param id Only return models with the given version.
     * @param category Only return models with the given category.
     * @param categoryLike Only return models with a category like the given name.
     * @param categoryNotEquals Only return models which do not have the given category.
     * @param name Only return models with the given name.
     * @param nameLike Only return models with a name like the given name.
     * @param key Only return models with the given key.
     * @param deploymentId Only return models with the given category.
     * @param version Only return models with the given version.
     * @param latestVersion If true, only return models which are the latest version. Best used in combination with key. If false is passed in as value, this is ignored and all versions are returned.
     * @param deployed If true, only deployed models are returned. If false, only undeployed models are returned (deploymentId is null).
     * @param tenantId Only return models with the given tenantId.
     * @param tenantIdLike Only return models with a tenantId like the given value.
     * @param withoutTenantId If true, only returns models without a tenantId set. If false, the withoutTenantId parameter is ignored.
     * @param sort Property to sort on, to be used together with the order.
     * @return DataResponseModelResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseModelResponse listModels(String id, String category, String categoryLike, String categoryNotEquals, String name, String nameLike, String key, String deploymentId, Integer version, Boolean latestVersion, Boolean deployed, String tenantId, String tenantIdLike, Boolean withoutTenantId, String sort) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/repository/models").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", id));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "category", category));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "categoryLike", categoryLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "categoryNotEquals", categoryNotEquals));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "name", name));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "nameLike", nameLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "key", key));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "deploymentId", deploymentId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "version", version));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "latestVersion", latestVersion));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "deployed", deployed));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantIdLike", tenantIdLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "withoutTenantId", withoutTenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "sort", sort));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseModelResponse> returnType = new ParameterizedTypeReference<DataResponseModelResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Set the extra editor source for a model
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     * <p><b>204</b> - Indicates the model was found and the extra source has been updated.
     * <p><b>404</b> - Indicates the requested model was not found.
     * @param modelId The modelId parameter
     * @param file The file parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void setExtraEditorSource(String modelId, File file) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'modelId' is set
        if (modelId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'modelId' when calling setExtraEditorSource");
        }

        // verify the required parameter 'file' is set
        if (file == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'file' when calling setExtraEditorSource");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("modelId", modelId);
        String path = UriComponentsBuilder.fromPath("/repository/models/{modelId}/source-extra").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        if (file != null)
            formParams.add("file", new FileSystemResource(file));

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = {
            "multipart/form-data"
        };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Set the editor source for a model
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     * <p><b>204</b> - Indicates the model was found and the source has been updated.
     * <p><b>404</b> - Indicates the requested model was not found.
     * @param modelId The modelId parameter
     * @param file The file parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void setModelSource(String modelId, File file) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'modelId' is set
        if (modelId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'modelId' when calling setModelSource");
        }

        // verify the required parameter 'file' is set
        if (file == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'file' when calling setModelSource");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("modelId", modelId);
        String path = UriComponentsBuilder.fromPath("/repository/models/{modelId}/source").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        if (file != null)
            formParams.add("file", new FileSystemResource(file));

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = {
            "multipart/form-data"
        };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Update a model
     * All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only updating the name of the model, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the model-value will be updated to null.
     * <p><b>200</b> - Indicates the model was found and updated.
     * <p><b>404</b> - Indicates the requested model was not found.
     * @param modelId The modelId parameter
     * @param body The body parameter
     * @return ModelResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ModelResponse updateModel(String modelId, ModelRequest body) throws RestClientException {
        Object postBody = body;

        // verify the required parameter 'modelId' is set
        if (modelId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'modelId' when calling updateModel");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("modelId", modelId);
        String path = UriComponentsBuilder.fromPath("/repository/models/{modelId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<ModelResponse> returnType = new ParameterizedTypeReference<ModelResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
